package edu.dayu;

import org.flowable.engine.IdentityService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootTest
public class ListenerDemo {
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;


    @Test
    void create(){
        Deployment deployment = repositoryService.createDeployment()
                .name("监听器demo")
                .addClasspathResource("processes/监听器demo.bpmn20.xml")
                .deploy();
        System.out.println(deployment);
    }

    @Test
    void start(){
        Map<String,Object> param = new HashMap<>();
        ProcessInstance r = runtimeService.startProcessInstanceByKey("listener-demo",param);
        System.out.println(r.getProcessInstanceId());
    }

    @Test
    void first(){
        List<Task> user = taskService.createTaskQuery().taskAssignee("dayu").list();
        System.out.println(user);
        Map<String,Object> param = new HashMap<>();
        taskService.complete(user.get(0).getId(),param);
    }
}
